# ------------------
# Public variables
CSC ?= gmcs
MONO ?= mono
PYTHON ?= python
PEG-SHARP ?= peg-sharp
GENDARME ?= /usr/local/bin/gendarme
INSTALL_DIR ?= /usr/local/bin

CSC_FLAGS ?= -checked+ -debug+ -warn:4 -warnaserror+ -d:DEBUG -d:TRACE -d:CONTRACTS_FULL

# ------------------
# Internal variables
dummy1 := $(shell mkdir bin 2> /dev/null)
peg-sharp := $(shell which $(PEG-SHARP))

# ------------------
# Primary targets
all: example

check: ftest

.PHONY: ftest
ftest: multimethod.py
	cd ftest && "$(PYTHON)" ftest.py

example: bin/example.exe

# ------------------
# Binary targets 
example/Evaluate.cs: multimethod.py
	$(PYTHON) multimethod.py --result=double --arg="Dictionary<string, double>:context" --arg=Expression:expr --name=Evaluate --dst=example

example/Parser.cs: example/Parser.peg $(peg-sharp)
	$(PEG-SHARP) --out=example/Parser.cs example/Parser.peg

bin/example.exe: example/Parser.cs example/Evaluate.cs example/*.cs
	$(CSC) -out:bin/example.exe $(CSC_FLAGS) -target:exe example/*.cs

# ------------------
# Misc targets
gendarme_flags := --severity all --confidence all --ignore gendarme.ignore --quiet
gendarme: bin/example.exe
	@-"$(GENDARME)" $(gendarme_flags) bin/example.exe

clean:
	-rm -rf bin/*.exe
	-rm -rf bin/*.exe.mdb
	-rm -rf bin/ftest

tar:
	tar --create --compress --exclude \*/.svn --exclude \*/.svn/\* --file=multimethod-sharp-0.3.tar.gz \
		MIT.X11 Makefile README TODO example ftest gendarme.ignore multimethod.py

install:
	install "multimethod.py" "$(INSTALL_DIR)/multimethod"

uninstall:
	-rm "$(INSTALL_DIR)/multimethod"

help:
	@echo "multimethod - A multiple dispatch code generator for C#."
	@echo " "
	@echo "The primary targets are:"
	@echo "check            - runs the functional tests"
	@echo "example          - builds the example app"
	@echo "clean            - removes generated files from the bin directory"
	@echo "install          - copies the script to $(INSTALL_DIR)"
	@echo "uninstall        - removes the script from $(INSTALL_DIR)"
